package org.xbill.DNS;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

public class ResolverConfig
{
  private static ResolverConfig currentConfig;
  private Name[] searchlist;
  private String[] servers = null;

  static
  {
    refresh();
  }

  public ResolverConfig()
  {
    this.searchlist = null;
    if (findProperty());
    while (true)
    {
      while (true)
      {
        String str2;
        while (true)
        {
          String str1;
          while (true)
          {
            while (true)
            {
              do
                return;
              while ((findSunJVM()) || ((this.servers != null) && (this.searchlist != null)));
              str1 = System.getProperty("os.name");
              str2 = System.getProperty("java.vendor");
              if (str1.indexOf("Windows") == -1)
                break label113;
              if ((str1.indexOf("95") == -1) && (str1.indexOf("98") == -1) && (str1.indexOf("ME") == -1))
                break;
              find95();
            }
            findNT();
          }
          label113: if (str1.indexOf("NetWare") == -1)
            break;
          findNetware();
        }
        if (str2.indexOf("Android") == -1)
          break;
        findAndroid();
      }
      findUnix();
    }
  }

  private void addSearch(String paramString, List paramList)
  {
    Name localName;
    if (Options.check("verbose"))
      System.out.println("adding search " + paramString);
    try
    {
      localName = Name.fromString(paramString, Name.root);
      if (paramList.contains(localName))
        label50: return;
    }
    catch (TextParseException localTextParseException)
    {
      break label50:
      paramList.add(localName);
    }
  }

  private void addServer(String paramString, List paramList)
  {
    if (paramList.contains(paramString));
    while (true)
    {
      return;
      if (Options.check("verbose"))
        System.out.println("adding server " + paramString);
      paramList.add(paramString);
    }
  }

  private void configureFromLists(List paramList1, List paramList2)
  {
    if ((this.servers == null) && (paramList1.size() > 0))
      this.servers = ((String[])paramList1.toArray(new String[0]));
    if ((this.searchlist == null) && (paramList2.size() > 0))
      this.searchlist = ((Name[])paramList2.toArray(new Name[0]));
  }

  private void find95()
  {
    try
    {
      Runtime.getRuntime().exec("winipcfg /all /batch " + "winipcfg.out").waitFor();
      findWin(new FileInputStream(new File("winipcfg.out")));
      new File("winipcfg.out").delete();
      return;
    }
    catch (Exception localException)
    {
    }
  }

  private void findAndroid()
  {
    ArrayList localArrayList;
    try
    {
      String str2;
      localArrayList = new ArrayList();
      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("getprop").getInputStream()));
      do
      {
        StringTokenizer localStringTokenizer;
        do
        {
          String str1 = localBufferedReader.readLine();
          if (str1 == null)
          {
            configureFromLists(localArrayList, null);
            return;
          }
          localStringTokenizer = new StringTokenizer(str1, ":");
        }
        while (localStringTokenizer.nextToken().indexOf(".dns") <= -1);
        str2 = localStringTokenizer.nextToken().replaceAll("[ \\[\\]]", "");
      }
      while (((!(str2.matches("^\\d+(\\.\\d+){3}$"))) && (!(str2.matches("^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$")))) || (localArrayList.contains(str2)));
      localArrayList.add(str2);
    }
    catch (Exception localException)
    {
    }
  }

  private void findNT()
  {
    Process localProcess;
    try
    {
      localProcess = Runtime.getRuntime().exec("ipconfig /all");
      findWin(localProcess.getInputStream());
      localProcess.destroy();
      return;
    }
    catch (Exception localException)
    {
    }
  }

  private void findNetware()
  {
    findResolvConf("sys:/etc/resolv.cfg");
  }

  private boolean findProperty()
  {
    StringTokenizer localStringTokenizer1;
    StringTokenizer localStringTokenizer2;
    int i;
    ArrayList localArrayList1 = new ArrayList(0);
    ArrayList localArrayList2 = new ArrayList(0);
    String str1 = System.getProperty("dns.server");
    if (str1 != null)
    {
      localStringTokenizer1 = new StringTokenizer(str1, ",");
      if (localStringTokenizer1.hasMoreTokens())
        break label107;
    }
    String str2 = System.getProperty("dns.search");
    if (str2 != null)
    {
      localStringTokenizer2 = new StringTokenizer(str2, ",");
      if (localStringTokenizer2.hasMoreTokens())
        break label120;
    }
    configureFromLists(localArrayList1, localArrayList2);
    if ((this.servers != null) && (this.searchlist != null))
      i = 1;
    while (true)
    {
      while (true)
      {
        while (true)
        {
          return i;
          label107: addServer(localStringTokenizer1.nextToken(), localArrayList1);
        }
        label120: addSearch(localStringTokenizer2.nextToken(), localArrayList2);
      }
      i = 0;
    }
  }

  // ERROR //
  private void findResolvConf(String paramString)
  {
    // Byte code:
    //   0: new 165	java/io/FileInputStream
    //   3: dup
    //   4: aload_1
    //   5: invokespecial 261	java/io/FileInputStream:<init>	(Ljava/lang/String;)V
    //   8: astore_2
    //   9: new 183	java/io/BufferedReader
    //   12: dup
    //   13: new 185	java/io/InputStreamReader
    //   16: dup
    //   17: aload_2
    //   18: invokespecial 193	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;)V
    //   21: invokespecial 196	java/io/BufferedReader:<init>	(Ljava/io/Reader;)V
    //   24: astore_3
    //   25: new 180	java/util/ArrayList
    //   28: dup
    //   29: iconst_0
    //   30: invokespecial 243	java/util/ArrayList:<init>	(I)V
    //   33: astore 4
    //   35: new 180	java/util/ArrayList
    //   38: dup
    //   39: iconst_0
    //   40: invokespecial 243	java/util/ArrayList:<init>	(I)V
    //   43: astore 5
    //   45: aload_3
    //   46: invokevirtual 199	java/io/BufferedReader:readLine	()Ljava/lang/String;
    //   49: astore 7
    //   51: aload 7
    //   53: ifnonnull +21 -> 74
    //   56: aload_3
    //   57: invokevirtual 264	java/io/BufferedReader:close	()V
    //   60: aload_0
    //   61: aload 4
    //   63: aload 5
    //   65: invokespecial 201	org/xbill/DNS/ResolverConfig:configureFromLists	(Ljava/util/List;Ljava/util/List;)V
    //   68: return
    //   69: astore 14
    //   71: goto -3 -> 68
    //   74: aload 7
    //   76: ldc_w 266
    //   79: invokevirtual 269	java/lang/String:startsWith	(Ljava/lang/String;)Z
    //   82: ifeq +34 -> 116
    //   85: new 203	java/util/StringTokenizer
    //   88: dup
    //   89: aload 7
    //   91: invokespecial 270	java/util/StringTokenizer:<init>	(Ljava/lang/String;)V
    //   94: astore 8
    //   96: aload 8
    //   98: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   101: pop
    //   102: aload_0
    //   103: aload 8
    //   105: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   108: aload 4
    //   110: invokespecial 254	org/xbill/DNS/ResolverConfig:addServer	(Ljava/lang/String;Ljava/util/List;)V
    //   113: goto -68 -> 45
    //   116: aload 7
    //   118: ldc_w 272
    //   121: invokevirtual 269	java/lang/String:startsWith	(Ljava/lang/String;)Z
    //   124: ifeq +52 -> 176
    //   127: new 203	java/util/StringTokenizer
    //   130: dup
    //   131: aload 7
    //   133: invokespecial 270	java/util/StringTokenizer:<init>	(Ljava/lang/String;)V
    //   136: astore 10
    //   138: aload 10
    //   140: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   143: pop
    //   144: aload 10
    //   146: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   149: ifeq -104 -> 45
    //   152: aload 5
    //   154: invokeinterface 275 1 0
    //   159: ifeq -114 -> 45
    //   162: aload_0
    //   163: aload 10
    //   165: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   168: aload 5
    //   170: invokespecial 256	org/xbill/DNS/ResolverConfig:addSearch	(Ljava/lang/String;Ljava/util/List;)V
    //   173: goto -128 -> 45
    //   176: aload 7
    //   178: ldc_w 277
    //   181: invokevirtual 269	java/lang/String:startsWith	(Ljava/lang/String;)Z
    //   184: ifeq -139 -> 45
    //   187: aload 5
    //   189: invokeinterface 275 1 0
    //   194: ifne +10 -> 204
    //   197: aload 5
    //   199: invokeinterface 280 1 0
    //   204: new 203	java/util/StringTokenizer
    //   207: dup
    //   208: aload 7
    //   210: invokespecial 270	java/util/StringTokenizer:<init>	(Ljava/lang/String;)V
    //   213: astore 12
    //   215: aload 12
    //   217: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   220: pop
    //   221: aload 12
    //   223: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   226: ifeq -181 -> 45
    //   229: aload_0
    //   230: aload 12
    //   232: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   235: aload 5
    //   237: invokespecial 256	org/xbill/DNS/ResolverConfig:addSearch	(Ljava/lang/String;Ljava/util/List;)V
    //   240: goto -19 -> 221
    //   243: astore 6
    //   245: goto -185 -> 60
    //
    // Exception table:
    //   from	to	target	type
    //   0	9	69	java/io/FileNotFoundException
    //   45	60	243	java/io/IOException
    //   74	240	243	java/io/IOException
  }

  private boolean findSunJVM()
  {
    int i;
    List localList1;
    List localList2;
    ArrayList localArrayList1 = new ArrayList(0);
    ArrayList localArrayList2 = new ArrayList(0);
    try
    {
      Class[] arrayOfClass = new Class[0];
      Object[] arrayOfObject = new Object[0];
      Class localClass = Class.forName("sun.net.dns.ResolverConfiguration");
      Object localObject = localClass.getDeclaredMethod("open", arrayOfClass).invoke(null, arrayOfObject);
      localList1 = (List)localClass.getMethod("nameservers", arrayOfClass).invoke(localObject, arrayOfObject);
      localList2 = (List)localClass.getMethod("searchlist", arrayOfClass).invoke(localObject, arrayOfObject);
      if (localList1.size() == 0)
      {
        i = 0;
        label211: return i;
      }
    }
    catch (Exception localException)
    {
      Iterator localIterator1;
      Iterator localIterator2;
      while (true)
        i = 0;
      if (localList1.size() > 0)
        localIterator2 = localList1.iterator();
      while (true)
      {
        while (!(localIterator2.hasNext()))
        {
          if (localList2.size() > 0)
          {
            localIterator1 = localList2.iterator();
            if (localIterator1.hasNext())
              break label211;
          }
          configureFromLists(localArrayList1, localArrayList2);
          i = 1;
        }
        addServer((String)localIterator2.next(), localArrayList1);
      }
      addSearch((String)localIterator1.next(), localArrayList2);
    }
  }

  private void findUnix()
  {
    findResolvConf("/etc/resolv.conf");
  }

  // ERROR //
  private void findWin(java.io.InputStream paramInputStream)
  {
    // Byte code:
    //   0: new 90	java/lang/StringBuilder
    //   3: dup
    //   4: ldc 2
    //   6: invokevirtual 325	java/lang/Class:getPackage	()Ljava/lang/Package;
    //   9: invokevirtual 330	java/lang/Package:getName	()Ljava/lang/String;
    //   12: invokestatic 334	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   15: invokespecial 95	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   18: ldc_w 336
    //   21: invokevirtual 99	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   24: invokevirtual 103	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   27: invokestatic 342	java/util/ResourceBundle:getBundle	(Ljava/lang/String;)Ljava/util/ResourceBundle;
    //   30: astore_2
    //   31: aload_2
    //   32: ldc_w 344
    //   35: invokevirtual 347	java/util/ResourceBundle:getString	(Ljava/lang/String;)Ljava/lang/String;
    //   38: astore_3
    //   39: aload_2
    //   40: ldc_w 349
    //   43: invokevirtual 347	java/util/ResourceBundle:getString	(Ljava/lang/String;)Ljava/lang/String;
    //   46: astore 4
    //   48: aload_2
    //   49: ldc_w 351
    //   52: invokevirtual 347	java/util/ResourceBundle:getString	(Ljava/lang/String;)Ljava/lang/String;
    //   55: astore 5
    //   57: aload_2
    //   58: ldc_w 353
    //   61: invokevirtual 347	java/util/ResourceBundle:getString	(Ljava/lang/String;)Ljava/lang/String;
    //   64: astore 6
    //   66: new 185	java/io/InputStreamReader
    //   69: dup
    //   70: aload_1
    //   71: invokespecial 193	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;)V
    //   74: astore 7
    //   76: new 183	java/io/BufferedReader
    //   79: dup
    //   80: aload 7
    //   82: invokespecial 196	java/io/BufferedReader:<init>	(Ljava/io/Reader;)V
    //   85: astore 8
    //   87: new 180	java/util/ArrayList
    //   90: dup
    //   91: invokespecial 181	java/util/ArrayList:<init>	()V
    //   94: astore 9
    //   96: new 180	java/util/ArrayList
    //   99: dup
    //   100: invokespecial 181	java/util/ArrayList:<init>	()V
    //   103: astore 10
    //   105: iconst_0
    //   106: istore 11
    //   108: iconst_0
    //   109: istore 12
    //   111: aload 8
    //   113: invokevirtual 199	java/io/BufferedReader:readLine	()Ljava/lang/String;
    //   116: astore 17
    //   118: aload 17
    //   120: ifnonnull +17 -> 137
    //   123: aload_0
    //   124: aload 9
    //   126: aload 10
    //   128: invokespecial 201	org/xbill/DNS/ResolverConfig:configureFromLists	(Ljava/util/List;Ljava/util/List;)V
    //   131: aload 8
    //   133: invokevirtual 264	java/io/BufferedReader:close	()V
    //   136: return
    //   137: new 203	java/util/StringTokenizer
    //   140: dup
    //   141: aload 17
    //   143: invokespecial 270	java/util/StringTokenizer:<init>	(Ljava/lang/String;)V
    //   146: astore 18
    //   148: aload 18
    //   150: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   153: ifne +12 -> 165
    //   156: iconst_0
    //   157: istore 11
    //   159: iconst_0
    //   160: istore 12
    //   162: goto -51 -> 111
    //   165: aload 18
    //   167: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   170: astore 19
    //   172: aload 17
    //   174: ldc 205
    //   176: invokevirtual 47	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   179: bipush 255
    //   181: if_icmpeq +9 -> 190
    //   184: iconst_0
    //   185: istore 11
    //   187: iconst_0
    //   188: istore 12
    //   190: aload 17
    //   192: aload_3
    //   193: invokevirtual 47	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   196: bipush 255
    //   198: if_icmpeq +68 -> 266
    //   201: aload 18
    //   203: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   206: istore 21
    //   208: iload 21
    //   210: ifne +46 -> 256
    //   213: aload 19
    //   215: aconst_null
    //   216: invokestatic 118	org/xbill/DNS/Name:fromString	(Ljava/lang/String;Lorg/xbill/DNS/Name;)Lorg/xbill/DNS/Name;
    //   219: astore 23
    //   221: aload 23
    //   223: invokevirtual 356	org/xbill/DNS/Name:labels	()I
    //   226: iconst_1
    //   227: if_icmpeq -116 -> 111
    //   230: aload_0
    //   231: aload 19
    //   233: aload 10
    //   235: invokespecial 256	org/xbill/DNS/ResolverConfig:addSearch	(Ljava/lang/String;Ljava/util/List;)V
    //   238: goto -127 -> 111
    //   241: astore 15
    //   243: aload 8
    //   245: invokevirtual 264	java/io/BufferedReader:close	()V
    //   248: goto -112 -> 136
    //   251: astore 16
    //   253: goto -117 -> 136
    //   256: aload 18
    //   258: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   261: astore 19
    //   263: goto -62 -> 201
    //   266: aload 17
    //   268: aload 4
    //   270: invokevirtual 47	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   273: bipush 255
    //   275: if_icmpeq +45 -> 320
    //   278: aload 18
    //   280: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   283: ifne +27 -> 310
    //   286: aload 19
    //   288: ldc 205
    //   290: invokevirtual 359	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   293: ifne -182 -> 111
    //   296: aload_0
    //   297: aload 19
    //   299: aload 10
    //   301: invokespecial 256	org/xbill/DNS/ResolverConfig:addSearch	(Ljava/lang/String;Ljava/util/List;)V
    //   304: iconst_1
    //   305: istore 12
    //   307: goto -196 -> 111
    //   310: aload 18
    //   312: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   315: astore 19
    //   317: goto -39 -> 278
    //   320: iload 12
    //   322: ifne +15 -> 337
    //   325: aload 17
    //   327: aload 5
    //   329: invokevirtual 47	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   332: bipush 255
    //   334: if_icmpeq +45 -> 379
    //   337: aload 18
    //   339: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   342: ifne +27 -> 369
    //   345: aload 19
    //   347: ldc 205
    //   349: invokevirtual 359	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   352: ifne -241 -> 111
    //   355: aload_0
    //   356: aload 19
    //   358: aload 10
    //   360: invokespecial 256	org/xbill/DNS/ResolverConfig:addSearch	(Ljava/lang/String;Ljava/util/List;)V
    //   363: iconst_1
    //   364: istore 12
    //   366: goto -255 -> 111
    //   369: aload 18
    //   371: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   374: astore 19
    //   376: goto -39 -> 337
    //   379: iload 11
    //   381: ifne +15 -> 396
    //   384: aload 17
    //   386: aload 6
    //   388: invokevirtual 47	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   391: bipush 255
    //   393: if_icmpeq -282 -> 111
    //   396: aload 18
    //   398: invokevirtual 250	java/util/StringTokenizer:hasMoreTokens	()Z
    //   401: ifne +27 -> 428
    //   404: aload 19
    //   406: ldc 205
    //   408: invokevirtual 359	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   411: ifne -300 -> 111
    //   414: aload_0
    //   415: aload 19
    //   417: aload 9
    //   419: invokespecial 254	org/xbill/DNS/ResolverConfig:addServer	(Ljava/lang/String;Ljava/util/List;)V
    //   422: iconst_1
    //   423: istore 11
    //   425: goto -314 -> 111
    //   428: aload 18
    //   430: invokevirtual 211	java/util/StringTokenizer:nextToken	()Ljava/lang/String;
    //   433: astore 20
    //   435: aload 20
    //   437: astore 19
    //   439: goto -43 -> 396
    //   442: astore 13
    //   444: aload 8
    //   446: invokevirtual 264	java/io/BufferedReader:close	()V
    //   449: aload 13
    //   451: athrow
    //   452: astore 14
    //   454: goto -5 -> 449
    //   457: astore 24
    //   459: goto -323 -> 136
    //   462: astore 22
    //   464: goto -353 -> 111
    //
    // Exception table:
    //   from	to	target	type
    //   87	131	241	java/io/IOException
    //   137	208	241	java/io/IOException
    //   213	221	241	java/io/IOException
    //   221	238	241	java/io/IOException
    //   256	435	241	java/io/IOException
    //   243	248	251	java/io/IOException
    //   87	131	442	finally
    //   137	208	442	finally
    //   213	221	442	finally
    //   221	238	442	finally
    //   256	435	442	finally
    //   444	449	452	java/io/IOException
    //   131	136	457	java/io/IOException
    //   213	221	462	org/xbill/DNS/TextParseException
  }

  /**
   * @deprecated
   */
  public static ResolverConfig getCurrentConfig()
  {
    monitorenter;
    try
    {
      ResolverConfig localResolverConfig = currentConfig;
      monitorexit;
      return localResolverConfig;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public static void refresh()
  {
    ResolverConfig localResolverConfig = new ResolverConfig();
    monitorenter;
    try
    {
      currentConfig = localResolverConfig;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public Name[] searchPath()
  {
    return this.searchlist;
  }

  public String server()
  {
    String str;
    if (this.servers == null)
      str = null;
    while (true)
    {
      return str;
      str = this.servers[0];
    }
  }

  public String[] servers()
  {
    return this.servers;
  }
}